<template>
  <div>
    <el-card class="box-card">
      <h2>合同流程查询</h2>
      <el-form :model="statusForm" label-width="120px">
        <el-form-item label="合同状态:">
          <el-select v-model="statusForm.contractStatus" placeholder="请选择合同状态">
            <el-option label="全部" value=""></el-option>
            <el-option label="待分配" value="待分配"></el-option>
            <el-option label="待起草" value="待起草"></el-option>
            <el-option label="待定稿" value="待定稿"></el-option>
            <el-option label="待审批" value="待审批"></el-option>
            <el-option label="待签订" value="待签订"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="searchByStatus">查询</el-button>
          <el-button @click="resetStatusSearch">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="contracts" style="width: 100%">
        <el-table-column prop="contractId" label="合同ID" width="180"></el-table-column>
        <el-table-column prop="contractName" label="合同名称"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      statusForm: {
        contractStatus: ''
      },
      contracts: []
    };
  },
  created() {
    this.fetchContracts();
  },
  methods: {
    fetchContracts() {
      this.axios.get('/api/contract/get')
        .then(response => {
          this.contracts = response.data;
        })
        .catch(error => {
          console.error('获取合同信息出错:', error);
        });
    },
    searchByStatus() {
      const params = { status: this.statusForm.contractStatus };
      this.axios.get('/api/contract/searchByStatus', { params })
        .then(response => {
          this.contracts = response.data;
        })
        .catch(error => {
          console.error('按状态查询合同信息出错:', error);
        });
    },
    resetStatusSearch() {
      this.statusForm.contractStatus = '';
      this.fetchContracts();
    }
  }
}
</script>

<style scoped>
.box-card {
  margin: auto;
  width: 800px;
}
</style>
